<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      background-color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <router-link to="/home" tag="button">首页</router-link>
    <router-link to="/news/2" tag="button">新闻</router-link>
    <router-link to="/about" tag="button">关于我们</router-link>
    <hr>
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          <h1>
            首页
          </h1>
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h1>
            新闻页详情页
          </h1>
        </div>
      `,
      mounted(){
        console.log(this.$route)
      },
	  watch:{
		  $route(to, from){
			console.log(to,from);  
		  }
	  }
    }
    const About = {
      template: `
        <div>
          <h1>
            关于我们
          </h1>
        </div>
      `
    }
    // 创建路由对象
    const routes = [
      {
        path: '/home',
        component: Home
      },
      {
        path: '/news/:cateId',
        component: News
      },
      {
        path:'/about',
        component: About
      }
    ]
    const router = new VueRouter({
      routes
    })
    const vm = new Vue({
      el:'#app',
      router
    })
  </script>
</body>
</html>